package com.sbkj.shunbaowallet.mvp_lvxingxing.ui.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.sbkj.shunbaowallet.mvp_lvxingxing.MyApp;
import com.sbkj.shunbaowallet.mvp_lvxingxing.R;
import com.sbkj.shunbaowallet.mvp_lvxingxing.adapter.MyAdapter;
import com.sbkj.shunbaowallet.mvp_lvxingxing.contract.MainContract;
import com.sbkj.shunbaowallet.mvp_lvxingxing.framework.annotation.CreatePresenter;
import com.sbkj.shunbaowallet.mvp_lvxingxing.framework.mvp.BaseMvpActivity;
import com.sbkj.shunbaowallet.mvp_lvxingxing.presenter.MainPresenter;
import com.sbkj.shunbaowallet.mvp_lvxingxing.widgets.RvLoadMoreView;
import com.squareup.leakcanary.RefWatcher;

/**
 * Created by lvxingxing on 2017/12/12.
 *
 * @author lvxingxing
 */

@CreatePresenter(MainPresenter.class)
public class MainActivity extends BaseMvpActivity<MainContract.IMainActivity, MainContract.IMainModel, MainContract.IMainPresenter> implements MainContract.IMainActivity {
    private String TAG="MainActivity";
    @Override
    protected int layoutResId() {
        return R.layout.activity_main;
    }

    @Override
    protected void viewAction(Bundle savedInstanceState) {
        if (savedInstanceState != null) {
            Log.e("perfect-mvp", "MainActivity  onCreate 测试  = " + savedInstanceState.getString("test"));
        }

        findViewById(R.id.tv).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clickView();
            }
        });

        MyAdapter myAdapter = new MyAdapter(R.layout.item_load_more);
        myAdapter.setLoadMoreView(new RvLoadMoreView());
    }

    //测试内存泄露
    class LeakThread extends Thread {
        @Override
        public void run() {
            try {
                Thread.sleep(6 * 60 * 1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        Log.e("perfect-mvp", "MainActivity onSaveInstanceState 测试");
        outState.putString("test", "test_save");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        RefWatcher refWatcher = MyApp.getRefWatcher(this);//1
        refWatcher.watch(this);
    }

    @Override
    public void clickView() {
        getMvpPresenter().method3();
    }

}